import { ApiProperty, IntersectionType, OmitType, PartialType } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { IsBoolean, IsInt, IsOptional, Min } from "class-validator";

import { QueryDto } from "@/core/dto/query.dto";

import { CreateCommentDto } from "./create-comment.dto";

export class QueryCommentsDto extends IntersectionType(QueryDto, PartialType(OmitType(CreateCommentDto, [] as const))) {
    @IsOptional()
    @Transform(({ value }) => {
        if (value === "1" || value === "yes" || value === "true") return true;
        if (value === "0" || value === "no" || value === "false") return false;
        return value;
    }) // 在 QueryDto 中，参数是以 URL 中的查询参数携带，而 URL 都是字符串类型"false"/"true"，所以需要转换一下
    @IsBoolean()
    @ApiProperty({
        example: "true",
        description: "是否审核通过",
        required: false
    })
    status: boolean;

    @IsOptional()
    @Transform(({ value }) => Number(value))
    @IsInt()
    @Min(0)
    @ApiProperty({ description: "用户ID", example: 0, required: false })
    userId: number;
}
